{include file="header.htm" /}
<body class="bodystyle" style="overflow-y: scroll; cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page min-hg-c-20"> 
    <div class="fixed-bar">
        <div class="item-title">
            <a class="back_xin" href='{:weapp_url("Verify/Verify/verify_store")}' title="返回"><i class="iconfont e-fanhui"></i></a>
            <div class="subject">
                <h3>编辑门店</h3>
                <h5></h5>
            </div>
        </div>
    </div>
    <form class="form-horizontal" id="postForm">
        <input type="hidden" name="store_id" value="{$store.store_id}">
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit"><label for="store_name"><em>*</em>门店名称</label></dt>
                <dd class="opt" style="width: auto;">
                    <input type="text" name="store_name" id="store_name" value="{$store.store_name}" class="input-txt" placeholder="请输入门店名称" autocomplete="off">
                </dd>
            </dl>
            <!-- <dl class="row">
                <dt class="tit"><label>门店LOGO</label></dt>
                <dd class="opt">
                    <div class="dan-pane">
                        <div class="images_upload images_upload_html" style="display: inline-block;">
                            <a href="javascript:void(0);" onclick="GetUploadify(1, '', 'allimg', 'storeLogoCallBack');" class="img-upload mb15" title="点击上传" style="text-align: center; box-sizing: border-box;">
                                <div class="y-line" id="store_logo_y_line" {notempty name="$store.store_logo"} style="display: none;" {/notempty}></div>
                                <div class="x-line" id="store_logo_x_line" {notempty name="$store.store_logo"} style="display: none;" {/notempty}></div>
                                <img src="{$store.store_logo}" id="store_logo_src" {notempty name="$store.store_logo"} style="max-height: 100%; max-width: 100%;" {else/} style="display: none;max-height: 100%; max-width: 100%;" {/notempty}>
                            </a>
                            <a href="javascript:void(0)" onclick="clearSpecifyPic('store_logo', 'store_logo_src', 'store_logo_y_line', 'store_logo_x_line')" class="delect" title="删除"></a>
                            <input type="hidden" id="store_logo" name="store_logo" value="{$store.store_logo}">
                        </div>
                    </div>
                </dd>
            </dl> -->
            <dl class="row">
                <dt class="tit"><label for="store_phone"><em>*</em>联系电话</label></dt>
                <dd class="opt" style="width: auto;">
                    <input type="text" name="store_phone" id="store_phone" value="{$store.store_phone}" class="input-txt" placeholder="请输入门店手机" autocomplete="off" maxlength="11" onkeyup="this.value=this.value.replace(/[^\d]/g, '');" onpaste="this.value=this.value.replace(/[^\d]/g, '');">
                </dd>
            </dl>

            <!-- <dl class="row">
                <dt class="tit"><label for="store_intro">门店简介</label></dt>
                <dd class="opt" style="width: auto;">
                    <input type="text" name="store_intro" id="store_intro" value="{$store.store_intro}" class="input-txt" placeholder="请输入门店简介" autocomplete="off">
                </dd>
            </dl> -->

            <dl class="row">
                <dt class="tit"><label><em>*</em>门店地址</label></dt>
                <dd class="opt" style="width: auto;">
                    <select name="store_province" id="store_province" onchange="changeRegion(this, 1);">
                        <option value="0">请选择</option>
                        {volist name="$provinceList" id="vo"}
                        <option value="{$vo.id}" {eq name="$store.store_province" value="$vo.id"} selected {/eq}>{$vo.name}</option>
                        {/volist}
                    </select>
                    <select name="store_city" id="store_city" onchange="changeRegion(this, 2);" {empty name="$cityList"} class="none" {/empty}>
                        <option value="0">请选择</option>
                        {volist name="$cityList" id="vo"}
                        <option value="{$vo.id}" {eq name="$store.store_city" value="$vo.id"} selected {/eq}>{$vo.name}</option>
                        {/volist}
                    </select>
                    <select name="store_area" id="store_area" {empty name="$areaList"} class="none" {/empty}>
                        <option value="0">请选择</option>
                        {volist name="$areaList" id="vo"}
                        <option value="{$vo.id}" {eq name="$store.store_area" value="$vo.id"} selected {/eq}>{$vo.name}</option>
                        {/volist}
                    </select>
                </dd>
            </dl>

            <dl class="row">
                <dt class="tit"><label for="store_address"><em>*</em>详细地址</label></dt>
                <dd class="opt" style="width: auto;">
                    <input type="text" name="store_address" id="store_address" value="{$store.store_address}" class="input-txt" placeholder="请输入详细地址" autocomplete="off">
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit"><label for="store_point"><em>*</em>位置坐标</label></dt>
                <dd class="opt">
                    <input type="text" name="store_point" id="store_point" value="{$store.store_point}" class="input-txt" placeholder="经度,纬度,例:110.321,20.004" autocomplete="off">
                    <input type="hidden" id="store_point_hidden" value="{$store.store_point}"/>
                    <!-- <a href="JavaScript:void(0);" onclick="selectMap();">选择</a> -->
                    <p style="font-size: 12px;">仅支持百度地图，基础信息-附件拓展未配置百度地图AK无法便捷选点可以手动填写，<a href="http://api.map.baidu.com/lbsapi/getpoint/index.html" target="_blank">去获取</a></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit"><label for="store_business"><em>*</em>营业时间</label></dt>
                <dd class="opt">
                    <input type="text" name="store_business" id="store_business" value="{$store.store_business}" class="input-txt" placeholder="请选择营业时间" autocomplete="off">
                </dd>
            </dl>

            <!-- <dl class="row">
                <dt class="tit"><label>门店封面</label></dt>
                <dd class="opt">
                    <div class="dan-pane">
                        <div class="images_upload images_upload_html" style="display: inline-block;">
                            <a href="javascript:void(0);" onclick="GetUploadify(1, '', 'allimg', 'storeCoverpicCallBack');" class="img-upload mb15" title="点击上传" style="text-align: center; box-sizing: border-box;">
                                <div class="y-line" id="store_coverpic_y_line" {notempty name="$store.store_coverpic"} style="display: none;" {/notempty}></div>
                                <div class="x-line" id="store_coverpic_x_line" {notempty name="$store.store_coverpic"} style="display: none;" {/notempty}></div>
                                <img src="{$store.store_coverpic}" id="store_coverpic_src" {notempty name="$store.store_coverpic"} style="max-height: 100%; max-width: 100%;" {else/} style="display: none;max-height: 100%; max-width: 100%;" {/notempty}>
                            </a>
                            <a href="javascript:void(0)" onclick="clearSpecifyPic('store_coverpic', 'store_coverpic_src', 'store_coverpic_y_line', 'store_coverpic_x_line')" class="delect" title="删除"></a>
                            <input type="hidden" id="store_coverpic" name="store_coverpic" value="{$store.store_coverpic}">
                        </div>
                    </div>
                </dd>
            </dl> -->

            <div class="bot">
                <a href="JavaScript:void(0);" onclick="saveStore();" class="ncap-btn-big ncap-btn-green">保存</a>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    layui.use('laydate', function() {
        var laydate = layui.laydate;
        laydate.render({ elem: '#store_business', type: 'time', range: true });
    });

    // 获取联动地址
    function changeRegion(obj, type) {
        var parent_id = parseInt($(obj).val());
        if (!parent_id || 0 >= parent_id) {
            if (1 === parseInt(type)) {
                $('#store_city').addClass('none');
                $('#store_area').addClass('none');
            } else if (2 === parseInt(type)) {
                $('#store_area').addClass('none');
            }
            return false;
        }

        $.ajax({
            url : "{:url('Field/ajax_get_region_data')}",
            data: {parent_id: parent_id, _ajax: 1},
            type: 'post',
            dataType: 'json',
            success: function(res) {
                if (res.region_html) {
                    // 输出下一级栏目选项
                    if (1 === parseInt(type)) {
                        res = '<option value="0">请选择</option>'+ res.region_html;
                        $('#store_city').empty().html(res).removeClass('none');
                        $('#store_area').empty().addClass('none');
                    } else if (2 === parseInt(type)) {
                        res = '<option value="0">请选择</option>'+ res.region_html;
                        $('#store_area').empty().html(res).removeClass('none');
                    }
                }
            },
            error: function(e) {
                layer.closeAll();
                layer.alert(e.responseText, {icon: 5});
            }
        });
    }

    // 选择位置
    function selectMap() {
        layer.open({
            type : 2,
            title: '选择位置',
            shadeClose: false,
            shade: layer_shade,
            closeBtn: 3,
            area: ['50%', '77%'],
            btn: ['确定','取消'],
            content: "{:weapp_url('Verify/Verify/select_map')}",
            yes: function(index, layero) {
                var val = $("#store_point_hidden").val();
                $("#store_point").val(val);
                layer.closeAll();
            }
        });
    }

    // 门店LOGO图片回调
    function storeLogoCallBack(paths) {
        $('#store_logo').val(paths);
        $('#store_logo_src').show().attr('src', paths);
        $('#store_logo_y_line, #store_logo_x_line').hide();
    }

    // 门店封面图片回调
    function storeCoverpicCallBack(paths) {
        $('#store_coverpic').val(paths);
        $('#store_coverpic_src').show().attr('src', paths);
        $('#store_coverpic_y_line, #store_coverpic_x_line').hide();
    }

    // 清楚指定图片
    function clearSpecifyPic(id_0, id_1, id_2, id_3) {
        $('#' + id_0).val('');
        $('#' + id_2 + ', #' + id_3).show();
        $('#' + id_1).hide().attr('src', '');
    }

    // 保存门店
    function saveStore() {
        var storeArea = $('#store_area').hasClass('none');
        if ($('#store_name').val() == '') {
            showErrorMsg('请输入门店名称');
            $('#store_name').focus();
            return false;
        } else if ($('#store_phone').val() == '') {
            showErrorMsg('请输入门店手机');
            $('#store_phone').focus();
            return false;
        } else if ($('#store_province').val() == 0 || $('#store_province').val() == null) {
            showErrorMsg('请选择省份');
            return false;
        } else if ($('#store_city').val()  == 0 || $('#store_city').val() == null) {
            showErrorMsg('请选择城市');
            return false;
        } else if (!storeArea && ($('#store_area').val()  == 0 || $('#store_area').val() == null)) {
            showErrorMsg('请选择区域');
            return false;
        } else if ($('#store_address').val() == '') {
            showErrorMsg('请输入详细地址');
            $('#store_address').focus();
            return false;
        } else if ($('#store_business').val() == '') {
            showErrorMsg('请选择营业时间');
            return false;
        } else if ($('#store_point').val() == '') {
            showErrorMsg('请输入位置坐标');
            // selectMap();
            return false;
        }

        layer_loading('正在处理');
        $.ajax({
            type: 'post',
            url : "{:weapp_url('Verify/Verify/verify_store_edit', ['_ajax'=>1])}",
            data: $('#postForm').serialize(),
            dataType: 'json',
            success: function(res) {
                layer.closeAll();
                if (res.code == 1) {
                    layer.msg(res.msg, {icon: 1, shade: layer_shade, time: 1000}, function() {
                        window.location.href = res.url;
                    });
                } else {
                    showErrorMsg(res.msg);
                }
            },
            error: function(e) {
                layer.closeAll();
                showErrorAlert(e.responseText);
            }
        });
    }
</script>
{include file="footer.htm" /}